package main.java.com.lee.ordering;

/**
 * @Description TODO
 * @Author winston
 * @DateTime 2021/12/30
 */
public class OrderingDemo {
    private volatile static int x,y;
    private static int a, b;
    public static void main(String[] args) throws InterruptedException {
        int i = 0;
        for (; ; ) {
            i++;
            a = b = x = y = 0;
            Thread t1 =new Thread(()->{
                a=1;
                x=b;
            });
            Thread t2 =new Thread(()->{
                b=1;
                y=a;
            });
            t1.start();
            t2.start();
            t1.join();
            t2.join();
            String result = "第" + i + "次(" + x + ", " + y + ")";
//            System.out.println(result);
            if (x == 0 && y == 0) {
                System.out.println(result);
            }
//            if (x == 1 && y == 1) {
//                System.out.println(result);
//            }
        }
    }
}
